package com.example.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.example.demo.bean.User;
import com.example.demo.mapper.UserMapper;

@Service
public class UserServices implements UserDetailsService {

	@Autowired
	private UserMapper userMapper;

	/**
	 * UserDetails这个对象是怎么封装的，完全来源于user对象
	 */
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		User user = userMapper.getUser(username);
		if (user == null) {
			throw new UsernameNotFoundException(username + ":" + "没有这个用户");
		}
		return user;
	}
}
